Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
mini-events
Advanced tools
:cake: 一个mini的事件管理器, 希望能在您的代码中做一块砖, 支持node/browser.
npm i -S mini-events
import EventEmitter from 'mini-events';
const emitter = new EventEmitter();
emitter.on('add', data=>{
console.log(data) // 1
});
emitter.emit('add', 1);
绑定事件
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | `String | Symbol` | 是 |
listener | 参数 | Function | 是 | 对应的回调函数 |
emitter | 返回值 | EventEmitter | --- | 实例 |
解除绑定, 如果不填写listener
, 那么eventName
对应的listener
都会被移除.
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | `String | Symbol` | 是 |
listener | 参数 | Function | 是 | 对应的回调函数 |
emitter | 返回值 | EventEmitter | --- | 实例 |
const callback = data=>{
alert(data)
};
emitter.on('add', callback);
// 解除绑定
emitter.on('off', callback);
// add事件不会触发
emitter.emit('add', 1);
绑定事件, 只触发一次
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | `String | Symbol` | 是 |
listener | 参数 | Function | 是 | 对应的回调函数 |
emitter | 返回值 | EventEmitter | --- | 实例 |
const callback = data=>{
alert(data)
};
emitter.once('add', callback);
// add事件触发
emitter.emit('add', 1);
// add事件不会触发
emitter.emit('add', 1);
触发事件, 支持任意数量参数
名称 | 类型 | 数据类型 | 是否必填 | 说明 |
---|---|---|---|---|
eventName | 参数 | `String | Symbol` | 是 |
...args | 参数 | Any | 是 | 对应的回调函数 |
emitter | 返回值 | Boolean | --- | 实例 |
const callback = (a,b,c,d)=>{
console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
// add事件触发
emitter.emit('add', 1,2,3,4);
销毁实例
const callback = (a,b,c,d)=>{
console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
emitter.destroy();
// add事件不会触发
emitter.emit('add', 1,2,3,4);
FAQs
🍰 一个mini事件管理器
The npm package mini-events receives a total of 1 weekly downloads. As such, mini-events popularity was classified as not popular.
We found that mini-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.